package app.controller.wechat;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.scyf.bean.TextMessageBean;
import com.scyf.weixintool.WeiXinMessageResolver;

public abstract class AbsEventHandle implements EventHandle {
	@Override
	public final void Handle(HttpServletResponse response, String xml) {
		EventHandle.super.Handle(response, xml);
	}
	
	@Override
	public void IMAGEResolver(HttpServletResponse response, String xml) throws Exception {
		// TODO Auto-generated method stub
		defaultHandler(response, xml, "我们会针对这些为您添加更有意思的功能");
	}
	@Override
	public void LINKResolver(HttpServletResponse response, String xml) throws Exception {
		// TODO Auto-generated method stub
		defaultHandler(response, xml, "我们会针对这些为您添加更有意思的功能");
	}
	@Override
	public void LOCATIONResolver(HttpServletResponse response, String xml) throws Exception {
		// TODO Auto-generated method stub
		defaultHandler(response, xml, "我们会针对这些为您添加更有意思的功能");
	}
	@Override
	public void SHORTVIDEOResolver(HttpServletResponse response, String xml) throws Exception {
		// TODO Auto-generated method stub
		defaultHandler(response, xml, "我们会针对这些为您添加更有意思的功能");
	}
	@Override
	public void TEXTResolver(HttpServletResponse response, String xml) throws Exception {
		// TODO Auto-generated method stub
		defaultHandler(response, xml, "我们会针对这些为您添加更有意思的功能");
	}
	@Override
	public void VIDEOResolver(HttpServletResponse response, String xml) throws Exception {
		// TODO Auto-generated method stub
		defaultHandler(response, xml, "我们会针对这些为您添加更有意思的功能");
	}
	@Override
	public void VOICEResolver(HttpServletResponse response, String xml) throws Exception {
		// TODO Auto-generated method stub
		defaultHandler(response, xml, "我们会针对这些为您添加更有意思的功能");
	}
	protected void defaultHandler(HttpServletResponse response, String xml,String message) throws Exception{
		// TODO Auto-generated method stub
		TextMessageBean textMessage = WeiXinMessageResolver.resolveTextMessage(xml);
		String responseXml = WeiXinMessageResolver.makeTextResponseXmlString(textMessage.getFromUserName(),
														textMessage.getToUserName(),
														message);
		response.setContentType("text/xml;charset=utf-8");
		PrintWriter writer = response.getWriter();
		writer.write(responseXml);
		writer.flush();
	}
	
}
